package com.basics.operator;

public class OperatorDemo3 {
    public static void main(String[] args) {
        //需求：掌握扩展的赋值运算符
        receive(10);
    }

    //需求：收红包
    public static void receive(int b) {
        //拿到自己钱包的金额
        int a = 100;
        a += b;//等价于a = （a的类型）a + b;
        System.out.println("收到红包后，我有" + a + "元钱");//110

        byte a1 = 10;
        byte b1 = 20;
        //a1 = a1 + b1;//编译失败，因为a1+b1是int类型，int类型赋值给byte类型，需要强制类型转换
        a1 += b1;//等价于a1 = (byte)(a1 + b1); 扩展赋值运算符自带强制类型转换
        System.out.println(a1);//30
    }

    //设计一个方法，演示其它扩展赋值运算符
    public static void test() {
        int a = 10;
        a -= 5;
        System.out.println(a);//5

        int b = 10;
        b *= 5;
        System.out.println(b);//50

        int c = 10;
        c /= 5;
        System.out.println(c);//2

        int d = 10;
        d %= 5;
        System.out.println(d);//0
    }
}
